SciChart WPF 2D Charts > Troubleshooting > Performance Tips & Tricks > Startup Application Performance
Startup Application Performance

Asynchronous DLLs loading

Async DLLs loading was introduces in SciChart WPF v6. This is a technique that should be used when you experience a delay when application starts. If this is the case, this delay may be caused by loading of the libraries that your application use.

Since v6, SciChart allows you to load the DLLs asynchronously. Please use the following code snippet in your application to load SciChart asynchronously:

App.xaml.cs
Copy Code
            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);
   
                // Async load libraries and apply license
                //
                // This code should be called and awaited before any SciChartSurface or SciChart3DSurface is shown
                //
                // Use SciChart.Charting3D.SciChart2D3DInitializer if you use both 2D & 3D charts in your app. Note this also initializes 2D libraries
                // Use SciChart.Charting.Visuals.SciChart2DInitializer if you use only 2D charts in your app
                //
                // Options: runtimeLicenseKey should be set to your license key
                //          tempDirectory is an optional temp directory for loading native libraries. Leave null for the default
   
                string runtimeLicenseKey = "your license keycode here";
                string tempDirectory = null;
   
                var initTask = SciChart2D3DInitializer.LoadLibrariesAndLicenseAsync(runtimeLicenseKey, tempDirectory);
   
                // You can either await initTask or use SciChart2D3DInitializer.Awaiter
                // to do the same thing later on (see MainWindow.xaml.cs)
            }
MainWindow.xaml.cs
Copy Code
            private async void MainWindowLoaded(object sender, RoutedEventArgs e)
            {
                // Wait for the license initialization we triggered in App.xaml.cs
                await SciChart2D3DInitializer.Awaiter;
   
                // Now swap out content for SciChartSurfaces once lienses loaded
                this.root.Children.Clear();
                this.root.Children.Add(new SciChartContent());
            }

Also, you can find a video tutorial about asynchronous SciChart loading on our YouTube channel and download a sample project from GitHub.

Asynchronous Visual Xcceletator Engine Startup

In SciChart WPF, hardware-accelerated rendering is possible due to the proprietary 3D engine called Visual Xccelerator Engine. Since SciChart v6.5, the Visual Xccelerator renderer is used as the default renderer. More info about renderers available in SciChart can be found in the "Renderer Plugins" article

However, starting and initializing the engine requires time. This time is usually spent during application startup. Reducing it may be critical in some cases. There are two solutions available in SciChart for this.

1. Disabling hardware-accelerated rendering and using a software renderer instead

This allows to avoid the delay at application startup caused by the engine initialization but comes with a drawback of slower chart rendering, because hardware-accelerated drawing is not used.

Visual Xccelerator Engine can be disabled via the VisualXcceleratorEngine.IsEnabledByDefault static property. It should be set to “False” before SciChartSurface constructor is called. In this case, a default software renderer (HighQuality renderer) will be used for drawing.

Alternatively, appropriate renderer can be applied directly via the RenderSurface property on SciChartSurface. Please find more info about renderers in SciChart and how to apply them in the "Renderer Plugins" article

2. Starting from SciChart v8.0, Visual Xccelerator Engine can be started asynchronously

This allows to avoid or reduce the Engine startup delay by making the Engine initialization happen when other application code is being executed.

By default, the Engine is started asynchronously during the Loaded event of SciChartSurface. Instead, it can be started manually through the API at any time before that. Since only one Engine instance can be running at the same time it doesn’t make much sense using the API to start the Engine after it is started by a SciChartSurface itself.

The API is quite simple. It is represented by a single static method that has a synchronous and an asynchronous version:

Synchronous and an asynchronous Engine start
Copy Code
public static void SciChart.Charting.VisualXcceleratorEngine.RestartEngine(VxRenderSettings renderSettings = null);
public static void SciChart.Charting.VisualXcceleratorEngine.RestartEngineAsync(VxRenderSettings renderSettings = null);

The usage can be demonstrated by the following code snippet. Here, the Engine starts in asynchronous manner in the App constructor:

Asynchronous start usage
Copy Code
        public App()
        {
            // Start Visual Xccelerator Engine asynchronously
            Task.Run(() =>
            {
                try
                {
                    VisualXcceleratorEngine.UseAutoShutdown = false;
                    VisualXcceleratorEngine.RestartEngine();
                }
                catch
                {
                    // Suppress Vx init errors. In this case rendering                    // will occur with a fallback to a software renderer
                }
            });
            // Do other app initialization
            InitializeComponent();
        }

Besides, it is possible to configure the Engine with desired VxRenderSettings and specify the shutdown option via the VisualXcceleratorEngine.UseAutoShutdown static property. Please find out more in the "Enabling The Visual Xccelerator Engine" article.

This approach is used in SciChart WPF Demo to reduce application startup time and guarantee that Visual Xccelerator Engine keeps running while switching between examples in the Demo. Please find the relevant code snippet in the Bootstrapper of the SciChart WPF Demo on GitHub.

See Also